package day15;

import java.util.*;

public class Homework {
    public static void main(String[] args) {
        String str="today is my birthday is my firsttime to leran java is";
        Map<String,Integer> map=new HashMap();
        for (String word:str.split(" ")){
            if (map.containsKey(word)){
                map.put(word,map.get(word)+1);
            }else{
                map.put(word,1);
            }
        }
        System.out.println(map);
    }
}


class Print{
    public static void main(String[] args) {
        String str="If you want to change your fate I think you must come to the ujiuye to learn java";
        Map<String,Integer> map=new TreeMap<>();
        for (String s:str.split(" ")){
            if (map.containsKey(s)){
                map.put(s,map.get(s)+1);
            }else{
                map.put(s,1);
            }
        }
        System.out.println(map);
        List<Map.Entry<String,Integer>> list=new ArrayList<>(map.entrySet());
        Collections.sort(list,(o1, o2) -> o2.getValue()- o1.getValue());
        for (Map.Entry<String, Integer> s:list){
            System.out.println(s);
        }
    }
}